<template>
  <div>
    <FilterTable
      ref="table"
      columnsRef="fyhRepairPro"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      height="auto"
      :isSelectColumn="false"
      :onColumnsChange="columns => (this.columns = columns)"
    ></FilterTable>

    <!-- 查看派工情况 -->
    <BaseDialog :visible.sync="workerLog" title="派工情况" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px', zIndex: '9999' }">
      <workerLogModel :selectColumns="this.selectColumns" @closeWorker="closeWorker" />
    </BaseDialog>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import workerLogModel from '@/pages/repair/repairReception/repairBusinessManger/repairTabs/workerLogModel';
import { queryRepairLabour, queryRepairPart, querySellMaterial, queryChargeDifferentiationList, queryRepairLabourCopy } from '@/api/repair/repairReception/repairBusinessManger';
import { getWxlxSelect } from '@/api/repair/repairReception/customer';
import { getBrand, getSeries, getModel, getRegion, getBxgsSelect } from '@/api/customerRepair/customerCare/insuranceDueRemind/index';
import { searchRoleByCode, searchRoleByCodes } from '@/api/common/empSelect/index';
import dictCode from '@/utils/dictCode';
export default {
  name: 'repairPro',
  components: {
    workerLogModel
  },
  mixins: [dictionary],
  props: ['dataList', 'roNo'],
  data() {
    return {
      columns: this.createTableColumns(),
      list: [],
      // fetchApi: queryRepairLabour,
      fetchApi: queryRepairLabourCopy,
      workerLog: false,
      fetchParams: {},
      selectColumns: []
    };
  },
  created() {
    let roNo = this.roNo;
    this.fetchParams = Object.assign({}, { roNo: roNo }, { xhrAbort: false });
  },
  mounted() {
    // this.queryRepairItem(); // 维修项目查询
    this.queryChargeList();
    this.serviceConsultant();
    // this.getWxtypeSelect();
    this.querySeries();
  },
  methods: {
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          sorter: true,
          render: props => {
            return (
              <el-button size="mini" type="text" onClick={() => this.openWorker(props)}>
                明细
              </el-button>
            );
          }
        },
        {
          title: '收费区分',
          dataIndex: 'CHARGE_PARTITION_CODE',
          sorter: true,
          filter: true,
          editable: false,
          editType: 'select',
          filterType: 'checkbox',
          filterItems: [],
          dictItems: []
        },
        {
          title: '项目维修类型',
          dataIndex: 'REPAIR_TYPE_NAME',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: false,
          editType: 'select',
          editItems: []
        },
        {
          title: '故障原因',
          dataIndex: 'TROUBLE_CAUSE',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '项目代码',
          dataIndex: 'LABOUR_CODEF',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '维修项目名称',
          dataIndex: 'LABOUR_NAME',
          width: 200,
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '套餐代码',
          dataIndex: 'PACKAGE_CODE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车系',
          dataIndex: 'MODEL_LABOUR_CODE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: []
        },
        {
          title: '主修人',
          dataIndex: 'TECHNICIAN',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          editable: false,
          editType: 'select',
          editItems: []
        },
        {
          title: '工时单价',
          dataIndex: 'LABOUR_PRICE',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2
        },
        {
          title: '标准工时',
          dataIndex: 'STD_LABOUR_HOUR',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          summationDataIndex: 'TOTAL_STD_LABOUR_HOUR'
        },
        {
          title: '工时费',
          dataIndex: 'LABOUR_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          summationDataIndex: 'TOTAL_LABOUR_AMOUNT'
        },
        {
          title: '派工工时',
          dataIndex: 'ASSIGN_LABOUR_HOUR',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          summationDataIndex: 'TOTAL_ASSIGN_LABOUR_HOUR'
        },

        {
          title: '索赔工时',
          dataIndex: 'CLAIM_LABOUR',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2
        },
        {
          title: '优惠金额',
          dataIndex: 'DISCOUNT_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          summationDataIndex: 'TOTAL_DISCOUNT_AMOUNT'
        },
        {
          title: '折扣率',
          dataIndex: 'DISCOUNT',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2
        },
        {
          title: '实收金额',
          dataIndex: 'RECEIVE_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          summationDataIndex: 'TOTAL_RECEIVE_AMOUNT'
        },

        // {
        //   title: '工种',
        //   dataIndex: 'WORKER_TYPE_CODE',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input',
        //   render: props => {
        //     return <span>{this.createDictText(props.row.WORKER_TYPE_CODE, '8041')}</span>;
        //   }
        // },
        // {
        //   title: '套餐类型',
        //   dataIndex: 'TCBLX',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input',
        //   render: props => {
        //     return <span>{this.createDictText(props.row.TCBLX, '8104')}</span>;
        //   }
        // },
        {
          title: '派工标志',
          dataIndex: 'ASSIGN_TAG',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            return <span>{this.createDictText(props.row.ASSIGN_TAG, '1004')}</span>;
          }
        },
        {
          title: '是否委外',
          dataIndex: 'CONSIGN_EXTERIOR',
          sorter: true,
          dictItems: this.createDictList(1004),
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList(1004)
        },
        {
          title: '是否不修',
          dataIndex: 'NEEDLESS_REPAIR',
          sorter: true,
          dictItems: this.createDictList(1004),
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList(1004)
        },
        {
          title: '不修类型',
          dataIndex: 'NEEDLESS_TYPE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1018'),
          dictItems: this.createDictList('1018')
        },
        {
          title: '不修原因',
          dataIndex: 'NEEDLESS_REASON',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '是否增项',
          dataIndex: 'IS_ADDITION',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList(1004),
          render: props => {
            return <el-checkbox checked={props.row.IS_ADDITION == 10041001} disabled></el-checkbox>;
          }
        },
        // {
        //   title: '责任技师',
        //   dataIndex: 'TECHNICIAN',
        //   sorter: true,
        //   filter: true,
        //   editable: false,
        //   editType: 'select',
        //   editItems: []
        // },
        // {
        //   title: '是否预检',
        //   dataIndex: 'PRE_CHECK',
        //   sorter: true,
        //   dictItems: this.createDictList(1004),
        //   filter: true,
        //   filterType: 'checkbox',
        //   filterItems: this.createDictList(1004)
        // },
        // {
        //   title: '是否内返',
        //   dataIndex: 'INTER_RETURN',
        //   sorter: true,
        //   dictItems: this.createDictList(1004),
        //   filter: true,
        //   filterType: 'checkbox',
        //   filterItems: this.createDictList(1004)
        // },
        {
          title: '活动编号',
          dataIndex: 'ACTIVITY_CODE',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            return <span>{props.row.ACTIVITY_CODE == 'null' ? (props.row.ACTIVITY_CODE = '') : props.row.ACTIVITY_CODE}</span>;
          }
        },
        // {
        //   title: '合同编号',
        //   dataIndex: 'SSP_CONTRACT_NO',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '检查结果',
        //   dataIndex: 'TROUBLE_DESC',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input',
        //   editable: false,
        //   editType: 'input'
        // },
        {
          title: '备注',
          dataIndex: 'REMARK',
          minWidth: 200,
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },

    // 查询收费区分
    async queryChargeList() {
      const res = await queryChargeDifferentiationList();
      // console.log(res, 'res');
      this.columns.find(x => x.dataIndex === 'CHARGE_PARTITION_CODE').dictItems = this.columns.find(x => x.dataIndex === 'CHARGE_PARTITION_CODE').filterItems = res.data.map(x => ({
        value: x.CHARGE_PARTITION_CODE + '',
        text: x.CHARGE_PARTITION_NAME
      }));
    },

    // 查询所有车系(供table使用)
    async querySeries() {
      const res = await getSeries();
      this.columns.find(x => x.dataIndex === 'MODEL_LABOUR_CODE').filterItems = res.data.map(x => ({
        text: x.SERIES_NAME,
        value: x.SERIES_NAME
      }));
    },

    // 查询维修项目
    // async queryRepairItem() {
    //   const roNo = this.roNo;
    //   const res = (await queryRepairLabour(roNo)).data.rows;
    //   this.list = res;
    // },

    // 获取维修项目类型
    // async getWxtypeSelect() {
    //   const res = await getWxlxSelect();
    //   this.columns.find(x => x.dataIndex === 'REPAIR_TYPE_NAME').editItems = res.data.map(x => ({
    //     value: x.REPAIR_TYPE_CODE + '',
    //     text: x.REPAIR_TYPE_NAME
    //   }));
    // },

    // 售前人员接口数据
    async serviceConsultant() {
      // let consultant = { role: dictCode.SERVICE_CONSULTANT }; // 服务顾问
      let technician = { role: '' }; // 指定技师 dictCode.TECHNICIAN
      // const consultantRes = await searchRoleByCode(consultant);
      const technicianRes = await searchRoleByCodes(technician);
      // this.topFilterList.find(x => x.fieldName === 'serviceAdvisor').itemList = consultantRes.data.map(x => ({ text: x.employeeName, value: x.userId + '' }));
      this.columns.find(x => x.dataIndex === 'TECHNICIAN').editItems = this.columns.find(x => x.dataIndex === 'TECHNICIAN').filterItems = technicianRes.data.map(x => ({
        text: x.employeeName,
        value: x.userId + ''
      }));
    },

    createBaseTable() {
      this.BaseTable = this.$refs.table.$refs.pageTable;
    },
    // // 传给父组件
    // syncTableFun(val) {
    //   if (val && val.length > 0) {
    //     delete val.dataMark;
    //     this.$emit('syncTablelist', val);
    //   } else {
    //     this.$emit('syncTablelist', []);
    //   }
    // },

    // 派工情况
    openWorker(props) {
      this.selectColumns = props.row;
      this.workerLog = true;
    },

    closeWorker(val) {
      console.log(1111);
      this.workerLog = val;
    }
  }
};
</script>

<style lang="less"></style>
